from PIL import Image

from torchvision.transforms import functional as F
import torchvision

from cnn_rotate.utils import img_util


def main():

    test_image_path = '../../dataset/landscape_dataset/input/3.jpg'

    img = Image.open(test_image_path).convert("RGB")

    pil_tensor = F.to_tensor(img)

    # img_np = np.array(img)
    #
    # img_torch = torch.from_numpy(img_np)
    #
    # #  H W C  --> C H W
    # img_torch = img_torch.permute(2, 0, 1)
    #
    # img_torch = img_torch.to(torch.float32).div_(255)

    angle_deg = 90

    pil_tensor = img_util.to_square(pil_tensor)
    # 旋转后的图片
    # img_torch_rotated = F.rotate(pil_tensor, angle_deg, F.InterpolationMode.BILINEAR)
    dst = img_util.rotate_square(pil_tensor, angle_deg)

    # torchvision.utils.save_image(img_torch_rotated, '1.jpg')

    # dst = F_t.resize(dst, [224, 224], antialias=True)
    torchvision.utils.save_image(dst, '2.jpg')


if __name__ == '__main__':
    main()
